<%--

    Copyright (C) 2009 alex <me@alex.0x08.org>

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

--%>

<%-- 
    Document   : comment
    Created on : 04.11.2010, 17:55:26
    Author     : alex
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="net.tanesha.recaptcha.ReCaptcha"%>
<%@ page import="net.tanesha.recaptcha.ReCaptchaFactory"%>


<stripes:form action="/action/AddComment"  >


    <stripes:errors/>

    <stripes:hidden name="code" value="${pageCode}"/>
    <stripes:hidden name="backUrl" value="${pageContext.request.requestURI}"/>

    <p> Комментировать:</p>

    <c:if test="${empty bzManager.currentUser}">
        <%
                    // create recaptcha without <noscript> tags
                    ReCaptcha captcha = ReCaptchaFactory.newReCaptcha("6LeJdb4SAAAAAPxK7fX5sz4gVzh2BIMU96mXfT1S", "6LeJdb4SAAAAAMB6JmsaURxYQxsDQaLb4QtS4gw6", false);
                    String captchaScript = captcha.createRecaptchaHtml(request.getParameter("error"), null);

                    out.print(captchaScript);
        %>
    </c:if>


    <table class="leftRightForm">
        <tr>

            <td><stripes:textarea name="message" rows="5" cols="50"/></td>
        </tr>

    </table>

    <div class="buttons">
        <stripes:submit name="save" value="Добавить комментарий"/>

    </div>
</stripes:form>



<c:if test="${not empty pageCode}">
    <jsp:setProperty name="bzManager" property="commentCode" value="${pageCode}" />
</c:if>

<c:forEach var="comment" items="${bzManager.comments}">

    <div class="reply">

        <div class='content'>
            <div class="messageHeader">
                <b>
                    <c:choose>
                        <c:when test="${not empty comment.author}">

                            <c:choose>

                                <c:when test='<%= request.isUserInRole("ROLE_ADMIN")%>'>

                                    <a href="<c:url value='/profile/${comment.author.id}'/>">
                                        <c:out value="${comment.author.firstName}"/> &nbsp;
                                        <c:out value="${comment.author.lastName}"/>
                                    </a>

                                </c:when>
                                <c:otherwise>
                                    <c:out value="${comment.author.firstName}"/> &nbsp;
                                    <c:out value="${comment.author.lastName}"/>

                                </c:otherwise>


                            </c:choose>

                        </c:when>
                        <c:otherwise>
                            Anonymous
                        </c:otherwise>
                    </c:choose>

                </b>

                <fmt:formatDate value="${comment.created}" dateStyle="medium"/>


            </div>

            <div class="post">
                <c:out value="${comment.message}"/>
            </div>

            <div class="post_bottom">
                <span class="left" >
                    <small>
                        <c:if test='<%= request.isUserInRole("ROLE_ADMIN")%>'>
                            MORE INFO FOR ADMIN
                        </c:if>
                    </small>

                </span>
                <span class="right" >
                    &nbsp;&nbsp;
                    <c:if test='<%= request.isUserInRole("ROLE_ADMIN")%>'>

                        <c:url var="deleteComment" value='/action/DeleteComment'>
                            <c:param name="commentId" value="${comment.id}"/>
                            <c:param name="backUrl" value="${pageContext.request.requestURI}"/>

                        </c:url>

                        <a href="<c:out value='${deleteComment}'/>">Удалить</a>


                    </c:if>




                </span>
            </div>




        </div>

    </div>

</c:forEach>
